	
$(function(){
	var bodyWidth = $(document.body).width();
	$("body>div").width(bodyWidth);

	var CurrentUser = GetLS("user");
	// hearder
	var head =  '<div class="cont_n nav_n">' + 
				'	<a href="index.html" class="fl"><img src="img/head_logo.png"></a>' + 
				'	<!-- 用户登录后 -->' + 
				'	<div id="mainName" class="fr" style="position:relative;">' + 
				'		<div class="fs14 loginW" style="width:154px;">' + 
				'    		<span class="btnY"><a href="javascript:void(0);" id="lbtn">登录</a></span>' + 
				'   		<span class="pada"><a href="javascript:void(0);" id="reg">注册</a></span>' + 
				'    	</div>' + 
				'   </div>'+
				'	<!-- 导航 -->' + 
				'	<ul class="top-nav_n fr" style="margin-right:20px">' + 
				'		<li id="index">首页</li>' +
				'		<li id="recommendCoursefree">公开课</li>' + 
				'		<li id="recommendCourse">课程</li>' + 
				'		<li id="recommendCertificate">证书</li>' + 
				// '		<li>资讯</li>' + 
				'		<li id="aa" style="position: relative;">' +
				'			<span>项目</span>' +
				'			<div class="lanmu">' +
				'				<p>项目</p>' +
				'				<div class="clear"></div>' +
				/*'				<p><a href="http://teacher.xiangxue8.com/" target="_blank">教师资格考试</a></p>' +*/
				'				<p><a href="/x8/w_extension.html" target="_blank">文化养老管理</a></p>' +
				 '				<p><a href="/x8/w_family.html" target="_blank">家政双提升项目</a></p>' +
				 '				<p><a href="/x8/w_marketing.html" target="_blank">新媒体数字营销</a></p>' +
				 '				<p><a href="/x8/zhuhai_pro.html" target="_blank">海珠区职工培训</a></p>' +
				'			</div>' +
				'		</li>' +
				'		<li id="app"><span style="background:url(img/head-pha.png)left center no-repeat;padding:8px;background-size:100%;"></span></li>'+
				'	</ul>' + 
				'</div>'+
				'<div style="height:1px;width:100%;background-color:#ccc;"></div>'+
				'<div style="height:2px;width:100%;background-color:#000;opacity:0.1;"></div>';

	$("#header").html(head);
	
	$("#lbtn").click(function(){
		var href = window.location.href.replace(window.location.search, "");
    	href = href.substring(href.lastIndexOf("/")+1);
    	href = href.split("#")[0];
		if(href == "index.html") {
			window.location.href = "index.html";
		}else {
			var htm = '<div class="theme-popover-mask"></div>'+
				'<div class="theme-popover ">'+
					'<!-- 藏 -->'+
					'<div class="theme-poptit box-sizing" >'+
						'<a href="javascript:;" title="关闭" class="close">×</a>'+
						'<span>登录</span>'+
					'</div>'+
					'<div class="theme-popbod dform">'+
						'<form class="theme-signin" name="loginform" action="" method="">'+
							'<ul>'+
								'<li><input class="ipt login-name box-sizing" type="text"  id="unm" placeholder="请输入用户名"/></li>'+
								'<li style="margin-bottom:10px"><input id="pwd" class="ipt login-pod  box-sizing" type="password" placeholder="请输入密码" /></li>'+
				                '<li style="position:relative"><input type="checkbox" id="remeber" checked class="rem-pow" /> <span >记住密码</span> <span class="right " id="findPasswordBtn" style="cursor:pointer">忘记密码</span></li>'+
								'<li><div class="btn btn-primary box-sizing" id="loginBtn">立即登录</div></li>'+
				                '<li><div class="registration" >还没有账号,<i id="regBtn" style="cursor:pointer">马上注册</i>！</div></li>'+
							'</ul>'+
						'</form>'+
					'</div>'+
				'</div>'+
				'<script type="text/javascript">'+
					'$("#loginBtn").click(Signup.lgn);'+
					'$("#findPasswordBtn").click(function(){'+
						// 'window.location.href = "a_findPassword.html";'+
						//'alert("休假中。。");'+
					'});'+
					'$("#pwd").keydown(function(event) {'+
						'if (event.keyCode == "13") {'+
							'$("#loginBtn").click();'+
						'}'+
					'});'+
					'$(".theme-poptit .close").click(function(){'+
						'$("#abcdefg").html("");'+
						'$(".theme-popover-mask").hide();'+
						'$(".theme-popover").slideUp(200);'+
					'});'+
					'$("#regBtn").click(function(){'+
						'window.location.href = "student-reg.html";'+
					'});'+
				'</script>';
			$("#abcdefg").html("");
			$("#abcdefg").html(htm);
		}
		$('.theme-popover-mask').show();
		$('.theme-popover-mask').height($(document).height());
		$('.theme-popover').slideDown(200);
		var saveUser = GetLS("saveUser");
				if (saveUser){
					$("#unm").val(saveUser.email);
					$("#pwd").val(saveUser.password);
			}
	});
	$("#reg").click(function(){
		window.location.href="student-reg.html";
	});
	
	// footer
	var foot = 	'<div class="cont_n">'+
				'	<div class="fl erweima">'+
				'		<img src="img/phone_f_n.png" alt="手机客户端">'+
				'		<p>手机客户端</p>'+
				'	</div>'+
				'	<div class="fl erweima">'+
				'		<img src="img/weixina.png" alt="微信客户端">'+
				'		<p>微信公众号</p>'+
				'	</div>'+
				'	<dl class="fl about_n">'+
				'		<dt><a href="index_guides.html?instr=le">关于我们</a></dt>'+
				'		<dd><a href="index_guides.html?instr=le">· 平台介绍</a></dd>'+
				'		<dd><a href="index_guides.html?instr=le">· 平台优势</a></dd>'+
				'		<dd><a href="index_guides.html?instr=le">· 平台成就</a></dd>'+
				'		<dd><a href="index_guides.html?instr=le">· 联系我们</a></dd>'+
				'	</dl>'+
				'	<dl class="fl about_n">'+
				'		<dt><a href="index_guides.html?instr=ri">新手指南</a></dt>'+
				'		<dd><a href="index_guides.html?instr=ri">· 注册登录</a></dd>'+
				'		<dd><a href="index_guides.html?instr=ri">· 选购课程</a></dd>'+
				'		<dd><a href="index_guides.html?instr=ri">· 支付开课</a></dd>'+
				'		<dd><a href="index_guides.html?instr=ri">· 申请证书</a></dd>'+
				'	</dl>'+
				'	<dl class="fl about_n" style="padding:4% 0% 4% 6%">'+
				'		<dt>意见反馈</dt>'+
				'		<dd><a href="javascript:">· 客服热线：010-58840096</a></dd>'+
				'		<dd><a href="javascript:">· 反馈邮箱：pxzxservice@ouchn.edu.cn</a></dd>'+
				'	</dl>'+
				'	<div class="clear"></div>'+
				'	<div class="company">'+
				'		<p>国开在线教育科技有限公司</p>'+
				'		<p>&copy; 2015 国开在线教育科技有限公司All rights reserved&nbsp;&nbsp;&nbsp;&nbsp; 京ICP备14044525号</p>'+
				'	</div>'+
				'</div>'+
				'<div class="floatRight">'+
				'	<ul>'+
				'		<li class="floatRighta">'+
				'			<div class="imgShow shadow_all none">'+
				'				<img src="img/floatWa_01.jpg">'+
				'			</div>'+
				'		</li>'+
				'		<li class="floatRightb">'+
				'			<div class="imgShow shadow_all none">'+
				'				<img src="img/floatWb_02.jpg">'+
				'			</div>'+
				'		</li>'+
				'		<li class="floatRightc">'+
				'			<div class="imgShow shadow_all none" style="padding:0">'+
				'				<p>客服电话<br>010-58840096</p>'+
				'				<p>反馈邮箱<br>pxzxservice@ouchn.edu.cn</p>'+
				'			</div>'+
				'		</li>'+
				'		<li class="floatRightd">'+
				'		   	<a href="a_index_app.html?stype=app" style="display: block;height: 52px;"></a>'+
				'			<div class="imgShow shadow_all none">'+
				'				<img src="img/floatWc_03.jpg">'+
				'			</div>'+
				'		</li>'+
				// '		<div class="wheSign" style="position: absolute;right: 0px;z-index: 111;cursor:pointer;">'+
				// '			<img src="img/floatWc_04.jpg">'+
				// '		</div>'+
				'	</ul>'+
				'</div>'+
				'<script>'+
				'var _hmt = _hmt || [];'+
				'(function() {'+
				'  var hm = document.createElement("script");'+
				'  hm.src = "//hm.baidu.com/hm.js?dfca5ab7f1472ea830f4981d12038260";'+
				'  var s = document.getElementsByTagName("script")[0]; '+
				'  s.parentNode.insertBefore(hm, s);'+
				'})();'+
				'</script>';
	$(".footer_n").html(foot);
	// 右侧浮动
	var loc = window.location.href;
	if(loc.indexOf('software_Spec.html') >= 0 || loc.indexOf('software.html') >= 0 || loc.indexOf('accounting_Spec.html') >= 0 || loc.indexOf('accounting_un.html') >= 0 || loc.indexOf('urban_rail.html') >= 0 || loc.indexOf('preschool_Spec.html') >= 0){
		$('.floatRight').attr('hidden',true);
	}
	$(".floatRight ul li").hover(function(){
		$(this).find("div").show();
	},function(){
		$(this).find("div").hide();
	});
	// 判断是否登陆
	$('.wheSign').click(function(){
		var CurrentUser = GetLS('user');
		if(CurrentUser.utype != 1000){
			if(CurrentUser.utype == UTYPE.STUDENT)
				locaHref('a_indexStudy.html?'+ random() +'#myCourseList');
			else
				locaHref('admin.html');
		}
		else{
			locaHref('index_logo.html');
		}
	})

	// if($(".footer_n").length > 0){
	// 	$(window).scroll(function(){
	// 		var panY = $(".floatRight").offset().top;
	// 		var scrH = $(this).scrollTop();
	// 		var winH = $(this).height()-50;
	// 		$(".floatRight").animate({top:scrH+winH/2},200);
	// 		console.log(scrH);
	// 	})
	// }
	// 公开课跳转
	$("#recommendCoursefree").click(function(){
		window.location.href = "a_indexMoreList.html?stype=coursefree";
	});
		
	$("#recommendCertificate").click(function(){
		window.location.href = "a_indexMoreList.html?stype=certificate";
	});		
	$("#recommendCourse").click(function(){
		window.location.href = "a_indexMoreList.html?stype=course";
	});
	$("#app").click(function(){
		window.location.href = "a_index_app.html?stype=app";
	});	
	$(".logo").click(function(){
		window.location.href = "index.html";
	});
	// console.log(CurrentUser);
	if (CurrentUser && CurrentUser.utype != 1000) {
		// $("#loginContent,#loginC").remove();
	 	var html =	'	<div class="login-user" id="mocont">' + 
					'		<p class="ellipsis">' + CurrentUser.name + '</p>' + 
					'		<span><img style="position:absolute;bottom:1.5px;right:4.5px;" src="img/icon_login.png"></span>' + 
					'		<!-- 隐藏个人中心 -->' + 
					'		<div class="top_person shadow_all none" style="display: none;">' + 
					'			<p id="personal" class="home_a">个人中心</p>' + 
					'			<p id="perfect" class="home_b">完善资料</p>' + 
					'			<p id="modipass" class="home_c">修改密码</p>' + 
					'			<p id="exit" class="home_d">退出</p>' + 
					'		</div>' + 
					' 		<!-- end -->' + 
					'	</div>' + 
					'	<div class="login-text" id="tou">' + 
					'	    <img src="img/1.jpg">' + 
					'	</div>';		
		$("#mainName").html(html);
		var src = "img/tou2.jpg";
		if (CurrentUser.photo){
			src = Core.id2url(CurrentUser.photo);
		}

		$("#tou").html('<img src="' + src + '" style="height:30px;width:30px;border-radius: 50%;right:-0.5em">');
		$("#exit").click(function(){
			if(CurrentUser && CurrentUser.utype != 1000){
	            $ajax({
	                url: "/users/logout",
	                data:{email: CurrentUser.email},
	                success: function(res) {
	                    ClearLS("user");
                    	ClearLS(CurrentUser);
	                    window.location.href = "/index.html?ran=" + Math.random();
	                }
	            });
	        }else{
	            ClearLS('user');
	            ClearLS(CurrentUser);
	            window.location.href = "/index.html?ran=" + Math.random();
	        }
		});
		
		// 弹出个人中心
		cour_n.homeTop(".login-user",".top_person");

		$("#perfect").click(function(){
			window.location.href = "a_modipassword.html?ty=pert#pert";
		});
		$("#modipass").click(function(){
			window.location.href = "a_modipassword.html?ty=modiP#modiP";
		});
	}
	// console.log(CurrentUser); // edit-1
	// 首页登录 add
	if (CurrentUser && CurrentUser.utype != UTYPE.VISITOR) {

		var courName = "";
		var courId = "" ;
		var htmlA = "";
		var htmlB = "";
		
		var hrefID = "studyT";
		if(CurrentUser.UTYPE == UTYPE.STUDENT){
			if(CurrentUser.features.lastCourse != undefined){
				courName = CurrentUser.features.lastCourse.name;
				courId = CurrentUser.features.lastCourse.id;
				pro = CurrentUser.features.lastCourse.proAttr;
				// add  判断课程有效期 0 跳转详细页面
				for(var g=0;g<CurrentUser.course.length;g++){
					if(CurrentUser.course[g].validity === 0){
						if(CurrentUser.course[g].name === courName){
							hrefID = "studyC"
						}
					}
				}

				// end
				htmlA = '<p class="fs16 ellipsis cf">'+courName+'</p>'+
						'<p class="h_40"></p>'+
						'<p class="btnRed fs16 btnHover" id="'+hrefID+'" data-id="'+courId+'" data-pro="'+ pro +'">继续学习</p>';
			}else{
				htmlA = '<p class="marB20" align="center"><img src="img/loginN.png"></p>'+
						'<p class="fs16 ellipsis" align="center" style="color:#e6e6e6">您还没有任何学习记录</p>';
			}
		}

		if(CurrentUser.utype == UTYPE.STUDENT){
			htmlB = '	<div class="logBom" id="noneStu">'+
					'		<p class="cf fs14 marB20">上次学习记录：</p>'+
					'		<div style="padding:0 20px">'+
					htmlA
					'		</div>'+
					'	</div>';
		}
		// $("#loginContent,#loginC").remove();
		var CurrentUser = GetLS("user");
		var htmla =	'<div class=" loginAfter">'+
					'	<div class="logTop">'+
					'		<p class="fl" id="tou"><img src="img/teacher.jpg"></p>'+
					'		<div class="fr personH"> '+
					'			<p class="fs20 over"><span class="ellipsis fl" style="width:130px;">' + CurrentUser.name + '</span><span class="fr fs14" style="line-height:30px;"><a href="javascript:void(0)" id="exit">退出</a></span></p>'+
					'			<p style="margin-top:16px"><a href="javascript:void(0)" id="personal">个人中心</a><i style="margin:0 10px;">|</i><a id="perfect" href="javascript:void(0)">修改资料</a></p>'+
					'		</div>'+
					'	</div>'+
					htmlB
					'</div>';	
			
		$("#indexHome").html(htmla);
		var src = "img/tou2.jpg";
		if (CurrentUser.photo){
			src = Core.id2url(CurrentUser.photo);
		}
		$("#tou").html('<img src="' + src + '" style="">');
		$("#exit").click(function(){
			if(CurrentUser && CurrentUser.utype != 1000){
	            $ajax({
	                url: "/users/logout",
	                data:{email: CurrentUser.email},
	                success: function(res) {
	                    ClearLS("user");
	            		ClearLS(CurrentUser);
	                    window.location.href = "/index.html?ran=" + Math.random();
	                }
	            });
	        }else{
	            ClearLS('user');
	            ClearLS(CurrentUser);
	            window.location.href = "/index.html?ran=" + Math.random();
	        }
		});
		
		$("#perfect").click(function(){
			window.location.href = "a_modipassword.html?ty=pert#pert";
		});
		$("#modipass").click(function(){
			window.location.href = "a_modipassword.html?ty=modiP#modiP";
		});

		// add
		$("#studyT").click(function(){
			var cid = $(this).data("id");
        	var couStatus = true;
        	for(var i=0;i<CurrentUser.course.length;i++){
        		if(cid == CurrentUser.course[i].id){
        			couStatus = CurrentUser.course[i].status;
        		}
        	}
        	if(couStatus){
        		if(cid){
					// if($(this).data('pro') == 1 || $(this).data('pro') == '1')
					// 	window.location.href ="studyPlan.html?stype=course&id="+$(this).data("id")+'&pro='+$(this).data('pro');
					// else
						window.location.href ="a_s_courseLearning.html?stype=course&id="+cid+'&pro='+$(this).data('pro');
				}else
					alert("没有课程！");
			}else
					alert("您的这门课程已锁定，请学习其他课程或联系相关人员！！！");
		});
			// add 超过有效期跳转
		$("#studyC").click(function(){
			window.location.href ="a_indexDetailCourseFirst.html?stype=course&id="+$(this).data("id");
		});
	}
	// end
	$("#index").click(function(){window.location.href="index.html"});
	$("#personal").click(IndexStudent.jump);
	$("#login").click(IndexStudent.showLogin);	
	$("#loginBtn").click(Signup.lgn);
	var reg = $.query.get("reg");
	if(reg == "1"){
		$("#loginBtn").click();
	}
	// nav
	var type = $.query.get("stype");
	if(type == "coursefree") {
		$(".top-nav_n li").eq(1).addClass("active_n");
	}
	else if(type == "course") {
		$(".top-nav_n li").eq(2).addClass("active_n");
	}
	else if(type == "certificate") {
		$(".top-nav_n li").eq(3).addClass("active_n");
	}
	else if(type == "app") {
		$(".top-nav_n li").eq(5).addClass("active_n");
	}

	// aboutMine
	var instr = $.query.get("instr");
	if(instr == "le") {
		$(".newhand span").eq(0).addClass("hand_bg");
		$(".hand_con .none").eq(0).css("display","block");
		$(".banner_zn").css("background","#2BA9BF url(img/about_a.jpg)center center no-repeat");
	}else if(instr == "ri"){
		$(".newhand span").eq(1).addClass("hand_bg");
		$(".hand_con .none").eq(1).css("display","block");
		$(".banner_zn").css("background","#3176C3 url(img/banner_zn.png)center center no-repeat");
	};

	// 六网跳转
	var liuwang = GetLS("liuwang");
	var pathname = window.location.pathname.substr(location.pathname.lastIndexOf("/")+1)
	var localpath = ["studyReport.html","studyLive.html","studyPlan.html","assReq.html","a_s_courseLearning.html","a_s_syllabus.html" ,"a_examinationRecords.html","a_scoreQualified.html","a_erroCollection.html","a_newsList.html","a_affiche.html","a_newsView.html","x_index_erroCheck.html","x_index_fraction.html","finalTest.html"];
	
	if(localpath.join(",").indexOf(pathname) !== -1){
		liuwang ? $("#header div").css({"visibility":"hidden"}).parent().css("min-height","50px").html(" ") : "";
	}else{
		window.localStorage.removeItem("liuwang");
	};
	// end

});
var cour_n = {
	// 首页头部
	homeTop:function(onClass,opClass){
		$(onClass).on('click',function(){
			if($(opClass).is(":hidden")){
				$(opClass).fadeIn(100);	
			}else{
				$(opClass).fadeOut(100);
			}
			$(opClass).mouseover(function(){
				$(this).show();
			});
			$(opClass).mouseout(function(){
				$(this).hide();
			});
		});
	}	
}
